import 'dart:collection';

import 'package:jd_shop/net/HttpHelper.dart';

import '../base/BaseUrl.dart';
import '../model/ClassLeft.dart';
import '../model/ClassRight.dart';
import '../model/GoodsDetailBean.dart';
import '../model/GoodsList.dart';
import '../model/LoveGoods.dart';

class MallmsService {
  MallmsService._();

  static final MallmsService _instance = MallmsService._();

  factory MallmsService() => _instance;

  static const String _LOVE_GOODS = "/mallms/mbHome/home/queryGoodsList";

  // 获取分类
  static const String _CLASS_LIST = "/mallms/wap/goods/itemcat/query";

  // 商品查询
  static const String _QUERY_GOODS = "/mallms/wap/shoplist/query/filter";

  // 商品详情
  static const String _QUERY_GOODS_DETAIL = "/mallms//wap/detail/goodsid/query";

  static Future<LoveGoods> getLoveGoods(params) async {
    var data = await HttpHelper.getInstance()?.postHttp<Map<String, dynamic>>(_LOVE_GOODS, params);
    return LoveGoods.fromJson(data!.data);
  }

  static Future<List<ClassLeft>?> getClassList() async {
    var params = HashMap<String, dynamic>();
    params["catParentId"] = 0;
    var data = await HttpHelper.getInstance()?.getHttp<List<dynamic>>(_CLASS_LIST, params);
    return data?.data.map((e) => ClassLeft.fromJson(e)).toList();
  }

  static Future<List<ClassRight>?> getRightClassList(catParentId) async {
    var params = HashMap<String, dynamic>();
    params["catParentId"] = catParentId;
    var data = await HttpHelper.getInstance()?.getHttp<List<dynamic>>(_CLASS_LIST, params);
    return data?.data.map((e) => ClassRight.fromJson(e)).toList();
  }

  static Future<List<GoodsList>?> QUERY_GOODS_List(HashMap params) async {
    var data = await HttpHelper.getInstance()?.postHttp<List<dynamic>>(_QUERY_GOODS, params);
    return data?.data.map((e) => GoodsList.fromJson(e)).toList();
  }

  static Future<GoodsDetailBean> queryGoodsDetailNet(HashMap params) async {
    var data = await HttpHelper.getInstance()?.postHttp<Map<String, dynamic>>(_QUERY_GOODS_DETAIL, params);
    return GoodsDetailBean.fromJson(data!.data);
  }

  //获取商品详情
  static String getGoodsDetailH5Url(Object commonId, Object goodsId) {
    return "${BaseUrl.baseUrl}/wap/pages/descshare.html?commonId=$commonId&&goodsId=$goodsId";
  }
}
